﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AuthCenter.Common.Common
{
    /// <summary>
    ///扩展类
    ///里面定义的是扩展方法
    ///用this作为类型扩展的关键字
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// 扩展字符串转数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ToInt32(this string? value) 
        {
            if (value == null)
            {
                return 0;
            }
            else 
            {
                return Convert.ToInt32(value);       
            }
        }
        /// <summary>
        /// 根据身份证计算出年月日
        /// </summary>
        /// <param name="carId">身份证号</param>
        /// <returns></returns>
        public static string GetBirthCarId(this string carId) 
        {
            string result = carId.Substring(6, 8);
            return result;
        }

        public static string GetBirthData(this DateTime  date) 
        {
            return date.ToString("yyyy-MM-dd");
        }
    }
}
